using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;

public partial class Home_ManageStudentAttributes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAddNewAttribute_Click(object sender, EventArgs e)
    {
        PlacementManagerLinqDataContext db = new PlacementManagerLinqDataContext();
        StudentAttribute s = new StudentAttribute();
        s.AttributeExpires = this.cbNewAttributeExpires.Checked;
        s.CreatedBy = User.Identity.Name;
        s.DateCreated = DateTime.Now;
        s.DateUpdated = DateTime.Now;
        s.DivisionId = Int32.Parse(Session["DivisionId"].ToString());
        s.IsActive = true;
        s.StudentAttributeName = this.txtNewAttributeName.Text;
        s.UpdatedBy = User.Identity.Name;

        db.StudentAttributes.InsertOnSubmit(s);
        db.SubmitChanges();

        this.gvStudentAttributes.DataBind();
        
        this.txtNewAttributeName.Text = string.Empty;
        this.cbNewAttributeExpires.Checked = false;
    }
    protected void gvStudentAttributes_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string user = User.Identity.Name;
        e.NewValues.Add("StudentAttributeId", this.gvStudentAttributes.DataKeys[e.RowIndex].Value.ToString());
        e.NewValues.Add("DateUpdated", DateTime.Now);
        e.NewValues.Add("UpdatedBy", user);        
    }
    protected void ldsStudentAttributes_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        PlacementManagerLinqDataContext db = new PlacementManagerLinqDataContext();
        var query = from sa in db.StudentAttributes
                    where sa.DivisionId == Int32.Parse(Session["DivisionId"].ToString())
                    select sa;
        e.Result = query;
    }
}
